# -*- coding: utf-8 -*-  
from django.shortcuts import render
from cmdb import models
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.shortcuts import HttpResponse

user_list=[
{"user":"jack","pwd":"abc"},
{"user":"tom","pwd":"ABC"},

]

@csrf_exempt
def index(request):
        print"进入index"
	if request.method=="POST":
		username=request.POST.get("username",None)
		password=request.POST.get("password",None)
		# print(username,password)
		# temp={"user":username,"pwd":password}
		models.UserInfo.objects.create(user=username,pwd=password)
		# user_list.append(temp)
	user_list=models.UserInfo.objects.all()
	return render(request, 'index.html', {'data': user_list})
#主页面



#######################下面是近义词操作########################################################
@csrf_exempt
def homoionym(request):
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		homoionym_word=request.POST.get("homoionym_word",None)
		models.homoionym.objects.create(origin_word=origin_word,homoionym_word=homoionym_word)
	user_list=models.homoionym.objects.all()
	return render(request, 'homoionym.html', {'data': user_list})
	#增

@csrf_exempt
def homoionym_delete(request):
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		homoionym_word=request.POST.get("homoionym_word",None)
		# models.antonym.objects.create(origin_word=origin_word,antonym_word=antonym_word)
		models.homoionym.objects.filter(origin_word=origin_word).delete()
	user_list=models.homoionym.objects.all()
	return render(request, 'homoionym_delete.html', {'data': user_list})
	#删

@csrf_exempt
def homoionym_modify(request):
	from django.db.models import Q
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		homoionym_word=request.POST.get("homoionym_word",None)
		models.homoionym.objects.filter(Q(origin_word=origin_word)|Q(homoionym_word=homoionym_word)).update(origin_word=origin_word,homoionym_word=homoionym_word)
	user_list=models.homoionym.objects.all()
	return render(request, 'homoionym_modify.html', {'data': user_list})
	#改


@csrf_exempt
def homoionym_query(request):
	from django.db.models import Q
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		homoionym_word=request.POST.get("homoionym_word",None)
		print ("origin_word=",origin_word)
		print ("homoionym_word=",homoionym_word)
		# models.homoionym.objects.filter(Q(origin_word=origin_word)|Q(homoionym_word=homoionym_word)).update(origin_word=origin_word,homoionym_word=homoionym_word)
	user_list=models.homoionym.objects.filter(Q(origin_word=origin_word)|Q(homoionym_word=homoionym_word))	
	return render(request, 'homoionym_modify.html', {'data': user_list})
	#查



#######################下面是反义词操作########################################################

@csrf_exempt
def antonym(request):
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		antonym_word=request.POST.get("antonym_word",None)
		models.antonym.objects.create(origin_word=origin_word,antonym_word=antonym_word)
	user_list=models.antonym.objects.all()
	return render(request, 'antonym.html', {'data': user_list})
	#增
@csrf_exempt
def antonym_delete(request):
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		antonym_word=request.POST.get("antonym_word",None)
		models.antonym.objects.filter(origin_word=origin_word).delete()
	user_list=models.antonym.objects.all()
	return render(request, 'antonym_delete.html', {'data': user_list})
	#删

@csrf_exempt
def antonym_modify(request):
	from django.db.models import Q
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		antonym_word=request.POST.get("antonym_word",None)
		models.antonym.objects.filter(Q(origin_word=origin_word)|Q(antonym_word=antonym_word)).update(origin_word=origin_word,antonym_word=antonym_word)
	user_list=models.antonym.objects.all()
	return render(request, 'antonym_modify.html', {'data': user_list})
	#改

@csrf_exempt
def antonym_query(request):
	from django.db.models import Q
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		antonym_word=request.POST.get("antonym_word",None)
		user_list=models.antonym.objects.filter(Q(origin_word=origin_word)|Q(antonym_word=antonym_word))	
	return render(request, 'antonym_query.html', {'data': user_list})
	#查


#######################下面是成语与成语故事操作########################################################

@csrf_exempt
def idiom_story(request):
	if request.method=="POST":
		idiom=request.POST.get("idiom",None)
		idiom_story=request.POST.get("idiom_story",None)
		models.idiom_story.objects.create(idiom=idiom,idiom_story=idiom_story)
	user_list=models.idiom_story.objects.all()
	return render(request, 'idiom_story.html', {'data': user_list})
	#增
@csrf_exempt
def idiom_story_delete(request):
	if request.method=="POST":
		idiom=request.POST.get("idiom",None)
		idiom_story=request.POST.get("idiom_story",None)
		models.idiom_story.objects.filter(idiom=idiom).delete()
	user_list=models.idiom_story.objects.all()
	return render(request, 'idiom_story_delete.html', {'data': user_list})
	#删

@csrf_exempt
def idiom_story_modify(request):
	from django.db.models import Q
	if request.method=="POST":
		idiom=request.POST.get("idiom",None)
		idiom_story=request.POST.get("idiom_story",None)
		models.idiom_story.objects.filter(Q(idiom=idiom)|Q(idiom_story=idiom_story)).update(idiom=idiom,idiom_story=idiom_story)
	user_list=models.idiom_story.objects.all()
	return render(request, 'idiom_story_modify.html', {'data': user_list})
	#改

@csrf_exempt
def idiom_story_query(request):
	from django.db.models import Q
	if request.method=="POST":
		idiom=request.POST.get("idiom",None)
		idiom_story=request.POST.get("idiom_story",None)
		user_list=models.idiom_story.objects.filter(Q(idiom=idiom)|Q(idiom_story=idiom_story))	
	return render(request, 'idiom_story_query.html', {'data': user_list})
	#查
#######################下面是黑名单操作########################################################
@csrf_exempt
def blacklists (request):
        print"进入blacklists"
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		models.blacklists.objects.create(origin_word=origin_word)
	user_list=models.blacklists.objects.all()
	return render(request, 'blacklists.html', {'data': user_list})#指定哪个网页接收请求和以及data
	#增
@csrf_exempt
def blacklists_delete(request):
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		models.blacklists.objects.filter(origin_word=origin_word).delete()
	user_list=models.blacklists.objects.all()
	return render(request, 'blacklists_delete.html', {'data': user_list})
	#删

@csrf_exempt
def blacklists_modify(request):
	from django.db.models import Q
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		models.blacklists.objects.filter(Q(origin_word=origin_word)).update(origin_word=origin_word)
	user_list=models.blacklists.objects.all()
	return render(request, 'blacklists_modify.html', {'data': user_list})
	#改

@csrf_exempt
def blacklists_query(request):
	from django.db.models import Q
	if request.method=="POST":
		origin_word=request.POST.get("origin_word",None)
		user_list=models.blacklists.objects.filter(Q(origin_word=origin_word))	
	return render(request, 'blacklists_query.html', {'data': user_list})
	#查
